<template>
	<view class="user-container">
		<!-- 顶部个人信息区域 -->
		<view class="user-info-section" :class="isLogin ? 'logged-in' : 'not-logged-in'">
			<template v-if="isLogin">
				<view class="user-info-wrapper">
					<view class="avatar-box">
						<image class="avatar" :src="userInfo.avatar" mode="aspectFill"></image>
					</view>
					<view class="user-detail">
						<view class="username">{{userInfo.nickname}}</view>
						<view class="user-id">ID: {{userInfo.userId}}</view>
						<view class="vip-tag" v-if="userInfo.isVip">
							<text class="iconfont icon-vip"></text>
							<text class="vip-text">VIP会员1</text>
						</view>
					</view>
					<view class="user-setting">
						<text class="iconfont icon-setting" @click="navigateTo('/pages/settings/index')">⚙️</text>
					</view>
				</view>
			</template>
			<template v-else>
				<view class="not-login-box" @click="goToLogin">
					<view class="not-login-content">
						<view class="avatar-box">
							<image class="avatar" src="/static/tabbar/user.png" mode="aspectFill"></image>
						</view>
						<view class="not-login-info">
							<view class="login-text">未登录</view>
							<view class="login-tip">登录后解锁更多个人功能</view>
						</view>
					</view>
				</view>
			</template>
		</view>
		
		<!-- 功能菜单区域 -->
		<view class="menu-section">
			<!-- 数据统计区 -->
			<view class="data-stats">
				<view class="stat-item" @click="navigateTo('/pages/errorbook/index')">
					<view class="stat-num">{{isLogin ? userInfo.errorCount : '--'}}</view>
					<view class="stat-name">错误本</view>
				</view>
				<view class="stat-item" @click="navigateTo('/pages/coupon/index')">
					<view class="stat-num">{{isLogin ? userInfo.couponCount : '--'}}</view>
					<view class="stat-name">优惠券</view>
				</view>
				<view class="stat-item" @click="navigateTo('/pages/member/index')">
					<view class="stat-num">{{isLogin ? (userInfo.isVip ? '已开通' : '未开通') : '--'}}</view>
					<view class="stat-name">会员权益</view>
				</view>
			</view>
			
			<!-- 功能菜单列表 -->
			<view class="menu-list">
				<view class="menu-title">功能服务</view>
				
				<view class="menu-item" @click="navigateTo('/pages/errorbook/index')">
					<view class="menu-item-left">
						<view class="icon-circle">
							<image src="/static/login/red.png" mode="aspectFit" class="menu-icon-image"></image>
						</view>
						<text class="menu-name">错误本</text>
					</view>
					<view class="menu-item-right">
						<text v-if="isLogin" class="menu-value">{{userInfo.errorCount}}个错题</text>
						→
					</view>
				</view>
				
				<view class="menu-item" @click="navigateTo('/pages/coupon/index')">
					<view class="menu-item-left">
						<view class="icon-circle">
							<image src="/static/login/yellow.png" mode="aspectFit" class="menu-icon-image"></image>
						</view>
						<text class="menu-name">优惠券</text>
					</view>
					<view class="menu-item-right">
						<text v-if="isLogin" class="menu-value">{{userInfo.couponCount}}张可用</text>
						→
					</view>
				</view>
				
				<view class="menu-item" @click="navigateTo('/pages/feedback/index')">
					<view class="menu-item-left">
						<view class="icon-circle">
							<image src="/static/login/blue.png" mode="aspectFit" class="menu-icon-image"></image>
						</view>
						<text class="menu-name">反馈与支持</text>
					</view>
					<view class="menu-item-right">
						→
					</view>
				</view>
				
				<view class="menu-item" @click="navigateTo('/pages/member/index')">
					<view class="menu-item-left">
						<view class="icon-circle">
							<image src="/static/login/orange.png" mode="aspectFit" class="menu-icon-image"></image>
						</view>
						<text class="menu-name">会员权益</text>
					</view>
					<view class="menu-item-right">
						<text v-if="isLogin" class="menu-value">{{userInfo.isVip ? '已开通' : '未开通'}}</text>
						→
					</view>
				</view>
				
				<view class="menu-item" @click="navigateTo('/pages/call-records/index')">
					<view class="menu-item-left">
						<view class="icon-circle">
							<image src="/static/login/green.png" mode="aspectFit" class="menu-icon-image"></image>
						</view>
						<text class="menu-name">通话记录与回放</text>
					</view>
					<view class="menu-item-right">
						<text v-if="isLogin" class="menu-value">{{userInfo.callCount}}条记录</text>
						→
					</view>
				</view>
			</view>
			
			<!-- 版本信息 -->
			<view class="version-info">
				<text class="version-text">版本 1.0.0</text>
			</view>
			
			<!-- 退出登录按钮，仅在登录状态显示 -->
			<view class="logout-section" v-if="isLogin">
				<button class="logout-btn" @click="logout">退出登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLogin: false, // 登录状态，false为未登录
				userInfo: {
					avatar: '/static/avatar.png',
					nickname: '用户昵称',
					userId: '10086',
					isVip: true,
					errorCount: 12,
					couponCount: 3,
					callCount: 5
				}
			}
		},
		onLoad() {
			// 检查登录状态
			this.checkLoginStatus();
		},
		onShow() {
			// 每次显示页面时检查登录状态
			this.checkLoginStatus();
		},
		methods: {
			// 检查登录状态
			checkLoginStatus() {
				// 这里应该从本地存储或API获取登录状态
				const token = uni.getStorageSync('token');
				this.isLogin = !!token;
			},
			
			// 跳转到登录页
			goToLogin() {
				uni.navigateTo({
					url: '/pages/login/index'
				});
			},
			
			// 页面导航
			navigateTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			
			// 退出登录
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 清除登录信息
							uni.removeStorageSync('token');
							this.isLogin = false;
							uni.showToast({
								title: '已退出登录',
								icon: 'none'
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	.user-container {
		min-height: 100vh;
		background-color: #f8f8f8;
	}
	
	/* 顶部用户信息区域样式 */
	.user-info-section {
		position: relative;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		background-color: #b0f6b1;
		color: black;
		border-bottom-left-radius: 40rpx;
		border-bottom-right-radius: 40rpx;
		box-shadow: 0 4rpx 20rpx rgba(138, 244, 217, 0.3);
	}
	
	.user-info-wrapper {
		display: flex;
		align-items: center;
		padding: 20rpx 0;
	}
	
	.avatar-box {
		width: 130rpx;
		height: 130rpx;
		border-radius: 65rpx;
		overflow: hidden;
		border: 4rpx solid rgba(255, 255, 255, 0.4);
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
	}
	
	.avatar {
		width: 100%;
		height: 100%;
	}
	
	.user-detail {
		margin-left: 30rpx;
		flex: 1;
	}
	
	.username {
		font-size: 38rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}
	
	.user-id {
		font-size: 24rpx;
		opacity: 0.8;
		margin-bottom: 10rpx;
	}
	
	.vip-tag {
		display: inline-flex;
		align-items: center;
		background: linear-gradient(to right, #FFD700, #FFA500);
		color: #8B4513;
		font-size: 22rpx;
		padding: 4rpx 12rpx;
		border-radius: 20rpx;
	}
	
	.vip-tag .iconfont {
		font-size: 22rpx;
		margin-right: 4rpx;
	}
	
	.user-setting {
		padding: 20rpx;
	}
	
	.user-setting .iconfont {
		font-size: 40rpx;
		color: rgba(255, 255, 255, 0.9);
	}
	
	/* 未登录样式 */
	.not-login-box {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 0;
	}
	
	.not-login-content {
		display: flex;
		align-items: center;
		flex: 1;
	}
	
	.not-login-info {
		margin-left: 30rpx;
		flex: 1;
	}
	
	.login-text {
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 8rpx;
	}
	
	.login-tip {
		font-size: 24rpx;
		opacity: 0.8;
	}
	
	.not-login-arrow {
		font-size: 30rpx;
		color: rgba(255, 255, 255, 0.7);
		margin-right: 10rpx;
	}
	
	/* 菜单区域样式 */
	.menu-section {
		padding: 30rpx;
	}
	
	/* 数据统计区域 */
	.data-stats {
		display: flex;
		justify-content: space-around;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 30rpx 0;
		margin-bottom: 30rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
	}
	
	.stat-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		flex: 1;
		position: relative;
	}
	
	.stat-item:not(:last-child):after {
		content: '';
		position: absolute;
		right: 0;
		top: 15%;
		height: 70%;
		width: 1px;
		background-color: #f0f0f0;
	}
	
	.stat-num {
		font-size: 40rpx;
		font-weight: bold;
		color: #8af4d9;
		margin-bottom: 10rpx;
	}
	
	.stat-name {
		font-size: 24rpx;
		color: #666;
	}
	
	/* 菜单列表 */
	.menu-list {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 0 30rpx;
		margin-bottom: 30rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
	}
	
	.menu-title {
		font-size: 32rpx;
		color: #333;
		font-weight: bold;
		padding: 30rpx 0 20rpx;
		border-bottom: 1rpx solid #f2f2f2;
	}
	
	.menu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f2f2f2;
	}
	
	.menu-item:last-child {
		border-bottom: none;
	}
	
	.menu-item-left {
		display: flex;
		align-items: center;
	}
	
	.icon-circle {
		width: 70rpx;
		height: 70rpx;
		border-radius: 35rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
		overflow: hidden;
	}
	
	.menu-icon-image {
		width: 100%;
		height: 100%;
	}
	
	.menu-name {
		font-size: 30rpx;
		color: #333;
		font-weight: 500;
	}
	
	.menu-item-right {
		display: flex;
		align-items: center;
		color: #999;
	}
	
	.menu-value {
		font-size: 26rpx;
		margin-right: 10rpx;
	}
	
	.icon-right {
		font-size: 24rpx;
		color: #bbb;
	}
	
	/* 版本信息 */
	.version-info {
		text-align: center;
		padding: 20rpx 0;
		margin-bottom: 30rpx;
	}
	
	.version-text {
		font-size: 24rpx;
		color: #999;
	}
	
	/* 退出登录按钮 */
	.logout-section {
		margin-top: 20rpx;
	}
	
	.logout-btn {
		width: 100%;
		background-color: #fff;
		color: #ff6b6b;
		border: 1rpx solid #f2f2f2;
		border-radius: 12rpx;
		font-size: 30rpx;
		font-weight: 500;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
	}
	
	/* 添加一些图标样式 */
	@font-face {
		font-family: "iconfont";
		src: url('https://at.alicdn.com/t/font_3094721_yx9thftzkh.ttf?t=1678705601846') format('truetype');
	}
	
	.iconfont {
		font-family: "iconfont" !important;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	
	.icon-error:before {
		content: "\e64d";
	}
	
	.icon-coupon:before {
		content: "\e638";
	}
	
	.icon-feedback:before {
		content: "\e60e";
	}
	
	.icon-vip:before {
		content: "\e628";
	}
	
	.icon-call:before {
		content: "\e625";
	}
	
	.icon-right:before {
		content: "\e7eb";
	}
	
	.icon-setting:before {
		content: "设置";
	}
</style> 